#include "TreeFunctors.h"

mUInt TreeFunctor::Delete::operator ()(CSceneNode *a_Node)
{
	delete a_Node;
	return CSceneTree::IRESULT_CONTINUE;
}

mUInt TreeFunctor::UpdateL2W::operator ()(CSceneNode *a_Node)
{
	a_Node->UpdateL2W();
	return CSceneTree::IRESULT_CONTINUE;
}

mUInt TreeFunctor::NotifyL2WChanged::operator ()(CSceneNode *a_Node)
{
	if (a_Node->SetL2WChanged())
		return CSceneTree::IRESULT_SKIPCHILD;
	return CSceneTree::IRESULT_CONTINUE;
}

TreeFunctor::TreeBoundBox::TreeBoundBox():
m_bBoxReaddy(false)
{

}

mUInt TreeFunctor::TreeBoundBox::operator ()(CSceneNode *a_Node)
{
	maths::CPointArray BoxPoints;
	a_Node->BoundBox().GetPoints(BoxPoints);
	BoxPoints.Transform(a_Node->GetL2W());
	m_Points.Push(BoxPoints);
	return CSceneTree::IRESULT_CONTINUE;
}

maths::CAABox &TreeFunctor::TreeBoundBox::GetBox()
{
	if (m_Points.Size() == 0)
		CSceneTree::Iterate(*this);
	if (!m_bBoxReaddy)
	{
		m_Points.CalcAABBox(m_Box);
		m_bBoxReaddy = true;
	}
	return m_Box;
}